package com.itheima.service.impl;

import com.itheima.dao.TbAssignRecordDao;
import com.itheima.pojo.TbAssignRecord;
import com.itheima.service.TbAssignRecordService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (TbAssignRecord)表服务实现类
 *
 * @author makejava
 * @since 2022-01-16 15:48:53
 */
@Service("tbAssignRecordService")
public class TbAssignRecordServiceImpl implements TbAssignRecordService {
    @Resource
    private TbAssignRecordDao tbAssignRecordDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TbAssignRecord queryById(Long id) {
        return this.tbAssignRecordDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param tbAssignRecord 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<TbAssignRecord> queryByPage(TbAssignRecord tbAssignRecord, PageRequest pageRequest) {
        long total = this.tbAssignRecordDao.count(tbAssignRecord);
        return new PageImpl<>(this.tbAssignRecordDao.queryAllByLimit(tbAssignRecord, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param tbAssignRecord 实例对象
     * @return 实例对象
     */
    @Override
    public TbAssignRecord insert(TbAssignRecord tbAssignRecord) {
        this.tbAssignRecordDao.insert(tbAssignRecord);
        return tbAssignRecord;
    }

    /**
     * 修改数据
     *
     * @param tbAssignRecord 实例对象
     * @return 实例对象
     */
    @Override
    public TbAssignRecord update(TbAssignRecord tbAssignRecord) {
        this.tbAssignRecordDao.update(tbAssignRecord);
        return this.queryById(tbAssignRecord.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.tbAssignRecordDao.deleteById(id) > 0;
    }
}
